package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Order;

@Repository
public interface OrderRepository extends JpaRepository<Order, Integer> {
	@Query("select sum(o.totalPrice.amount) from Order o")
	Double findTotalAmount();

	@Query("select o.buyer.id, sum(o.totalPrice.amount) from Order o group by o.buyer.id")
	Collection<Object[]> findMoreSpentByBuyer();
	
	@Query("select o from Order o where o.buyer.id = ?1")
	Collection<Order> findByBuyerId(int buyerId);
}
